﻿using FPSO.Models.Constant;
using FPSO.Services.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace FPSO.HMI.Task
{
    /// <summary>
    /// 任务实例，包含两个装载任务，和一个外输及倒舱任务
    /// </summary>
    public class TaskImpl
    {
        private static TaskImpl impl = new TaskImpl();
        private bool running;
        private LoadTaskExecuter loadTask1;
        private LoadTaskExecuter loadTask2;
        private Thread executeThread;
        private TaskImpl()
        {
            running = true;
            loadTask1 = new LoadTaskExecuter(TaskQueueConstant.LOAD_TASK_1_ID, new DBTankTaskService(), new DBInstructService());
            loadTask2 = new LoadTaskExecuter(TaskQueueConstant.LOAD_TASK_2_ID, new DBTankTaskService(), new DBInstructService());
            executeThread = new Thread(WorkerThread);
            executeThread.IsBackground = true;
            executeThread.Start();
        }

        public static TaskImpl GetInstance()
        {
            return impl;
        }

        private void WorkerThread()
        {
            while(running)
            {
                loadTask1.Worker();
                loadTask2.Worker();
                Thread.Sleep(3000);
            }
        }

        public void RunTask()
        {

        }

        public void StopTask()
        {

        }
    }
}
